package com.cl.mybatis.learn.day14;

import java.io.InputStream;

import com.cl.mybatis.learn.day14.bean.User;
import com.cl.mybatis.learn.day14.dao.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class Mybatis001 {
    public static void main(String[] args) throws Exception {
        
        String resource = "common1/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        User user = new User();
        user.setPassword("pass666");
        user.setUserName("user666");
        
        try {
//            mapper.insert(user);
//            mapper.insert2(user);
//            user= mapper.selectById2(1L);
            user= mapper.selectById3(1L);
            System.out.println("user：" + user);
        } finally {
            session.close();
        }
        
    }
    
}
